/*
 * Copyright (c) 2014 laidian. All Rights Reserved.
 * 
 * @author yaoyuming
 * 
 * @date 2019-12-23 9:39
 */
package com.yao.util;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.lang.Console;
import cn.hutool.core.util.StrUtil;
import cn.hutool.setting.dialect.Props;
import com.yao.constant.Const;
import com.yao.constant.ParamConst;

import java.util.Arrays;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * 自定义参数map
 *
 * @author yaoyuming
 * @date 2019/12/23 9:39
 */
public class CustMapUtil {

    private static final String PROP_FILE = "application.yml";
    private static final Map<String, String> map = CollUtil.newHashMap();

    static {
        // 默认包路径为本地路径 com.yao
        String packegeName = CustMapUtil.class.getPackage().getName();
        // 取包路径(com.yao)
        String basic =  Optional.ofNullable(Arrays.stream(packegeName.split("\\.")).limit(2).collect(Collectors.joining(".")))
                .orElse(Props.getProp(PROP_FILE).getStr(Const.BASE_PACKAGE));
        map.put("package", basic);

    }

    public static Map<String, String> get() {
        return map;
    }

    public static String get(String key) {
        return get().get(key);
    }

    public static void setPackage(String pkg, String destPath) {
        // 输出路径，绝对路径
        map.put(ParamConst.DEST_PATH, destPath);

        if (StrUtil.isNotEmpty(pkg)) {
            map.put("package", pkg);
            return;
        }
    }


}